<?php

class Application_Form_KalenderBearbeitenForm extends Zend_Form
{
	protected $_kalenderdatvon;
	protected $_kalenderdatbis;
	
	public function __construct($options = null, $kalenderdatvon = '', $kalenderdatbis = '')
    {
        $this->_kalenderdatvon = $kalenderdatvon;
        $this->_kalenderdatbis = $kalenderdatbis;
        parent::__construct($options);
    }
    
    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    	$decorator = new My_Decorator_SimpleInput();
    	$decoratorselect = new My_Decorator_SimpleSelect();
    	    	
    	$this->setName('Kalender bearbeiten');
		
		
		$datumBeginn   = new Zend_Form_Element('datumvon', array(
        'label'      => 'Von:',
        
        'value'      => '',
		'validators' => array(
                array('validator' => 'StringLength', 'options' => array(10, 10))
                )
    	));
    	$datumBeginn->setRequired()
    				->addErrorMessage('Ungültiges Datum')
    				->clearDecorators()
    				->addDecorator($decorator)
    				->addDecorator('Errors');

		//endedatum
    	$datumBis   = new Zend_Form_Element('datumbis', array(
        'label'      => 'Bis:',
        'value'      => '',
		'validators' => array(
                array('validator' => 'StringLength', 'options' => array(10, 10))
                )
    	));
    	$datumBis->setRequired()
    			->addErrorMessage('Ungültiges Datum')
    	    	->clearDecorators()
    			->addDecorator($decorator)
    			->addDecorator('Errors');
    			
    	$auswahl  = new Zend_Form_Element_Select('auswahl', array(
        'label'      => 'Den ausgewählten Zeitraum:',
        'value'      => '',
        'MultiOptions' => array(
       				'add' => 'hinzufügen',
       				'delete' => 'entfernen',
       				),
       			));
       	$auswahl->clearDecorators()
    			->addDecorator($decoratorselect)
    			->addDecorator('Errors');
    	
    	
		$submit = new Zend_Form_Element_Submit('abschicken',array('class' => 'button'));
		$submit->setLabel('Jetzt ausführen');
			   
		$form = new Zend_Form();
		
    	
		$this->addElements(array($datumBeginn,$datumBis,$auswahl,$submit));
		
		$this->setMethod('post');
    }
		public function loadDefaultDecorators() {
			 $this->setDecorators(
         array(
             array('ViewScript', 
                 array('viewScript' => 'kalender/bearbeiten.phtml')
             )
          )
      );     
		}
    


}

class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract
    {
        protected $_format = '<label for="%s">%s</label><input id="%s" name="%s" type="text" value="%s"/>';
     
        public function render($content)
        {
            $element = $this->getElement();
            $name    = htmlentities($element->getFullyQualifiedName());
            $label   = htmlentities($element->getLabel());
            $id      = htmlentities($element->getId());
            $value   = htmlentities($element->getValue());
     
            $markup  = sprintf($this->_format, $name, $label, $id, $name, $value);
            return $markup;
        }
    }

class My_Decorator_SimpleSelect extends Zend_Form_Decorator_Abstract
    {
        protected $_format = '<label for="%s">%s</label>';
     
        public function render($content)
        {
            $element = $this->getElement();
            $name    = htmlentities($element->getFullyQualifiedName());
            $label   = htmlentities($element->getLabel());
            $id      = htmlentities($element->getId());
            $value   = htmlentities($element->getValue());
            $options = $element->getMultiOptions();
     
            $markup  = sprintf($this->_format, $name, $label);
            $markup  = $markup . '<select name="' . $name . '" id="' . $id .'">';
        	foreach ($options as $intern => $extern) {
	     		$markup .= '<option value="'. $intern . '" label="' .$extern .'">' . $extern . '</option>';
	     		
	     	}
            $markup .= '</select>';
            return $markup;
        }
    }